package com.handpay.nocardpay.baselibrary.http;

import com.android.volley.Request;
import com.google.gson.reflect.TypeToken;
import com.handpay.nocardpay.baselibrary.http.request.ByteRequest;
import com.handpay.nocardpay.baselibrary.http.request.GsonRequest;
import com.handpay.nocardpay.baselibrary.http.request.JsonArrayRequest;
import com.handpay.nocardpay.baselibrary.http.request.JsonObjectRequest;
import com.handpay.nocardpay.baselibrary.http.request.StringRequest;
import com.handpay.nocardpay.baselibrary.logutils.HPLog;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * Created by sxshi on 2018-4-24.
 * http request factory
 *
 */

public class HttpRequestFactory {

    private HttpRequestFactory() {
        //can not be init
    }

    /**
     * @param httpRequest
     * @param listener
     * @return
     */
    public static Request request(HttpRequest httpRequest, HttpListener<String> listener) {
        return null;
    }

    /**
     * http request return byte data
     *
     * @param httpRequest
     * @param listener
     * @return
     */
    public static Request byteRequest(HttpRequest httpRequest, HttpListener<byte[]> listener) {
        ByteRequest request = new ByteRequest(httpRequest, listener);
        HPLog.d(HPLog.TAG_RESULT, "url:" + request.getUrl());
        return request;
    }

    /**
     * String request
     *
     * @param httpRequest
     * @param listener
     * @return
     */
    public static Request stringRequest(HttpRequest httpRequest, HttpListener<String> listener) {
        StringRequest request = new StringRequest(httpRequest, listener);
        HPLog.d(HPLog.TAG_RESULT, "url:" + request.getUrl());
        return request;
    }

    /**
     * http request Json Object
     *
     * @param httpRequest
     * @param listener
     * @return
     */
    public static Request jsonObjectRequest(HttpRequest httpRequest, HttpListener<JSONObject> listener) {
        JsonObjectRequest request = new JsonObjectRequest(httpRequest, listener);
        return request;
    }

    /**
     * http requst return JsonArray data
     *
     * @param httpRequest
     * @param listener
     * @return
     */
    public static Request jsonArrayRequest(HttpRequest httpRequest, HttpListener<JSONArray> listener) {
        JsonArrayRequest request = new JsonArrayRequest(httpRequest, listener);
        return request;
    }

    /**
     * http requst Gson data
     *
     * @param clzz
     * @param httpRequest
     * @param listener
     * @param <T>
     * @return
     */
    public static <T> Request gsonRequest(Class<T> clzz, HttpRequest httpRequest, HttpListener<T> listener) {
        GsonRequest<T> request = new GsonRequest<T>(clzz, httpRequest, listener);
        return request;
    }

    /**
     * http requst Gson data
     *
     * @param typeToken
     * @param httpRequest
     * @param listener
     * @param <T>
     * @return
     */
    public static <T> Request gsonRequest(TypeToken<T> typeToken, HttpRequest httpRequest, HttpListener<T> listener) {
        GsonRequest<T> request = new GsonRequest<T>(typeToken, httpRequest, listener);
        return request;
    }
}
